package org.glut.cloud.repairRecordManage.controller;

import org.glut.cloud.repairRecordManage.MaintenanceRecordsdto.Friends;
import org.glut.cloud.repairRecordManage.MaintenanceRecordsdto.Messages;
import org.glut.cloud.repairRecordManage.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/repair")
public class RepairRecordManageController {

    @Autowired
    private FriendService friendsService;

    // 获取好友列表
    @GetMapping("/friends/list")
    public List<Friends> getFriends(@RequestParam("userId") Integer userId) {
        return friendsService.getFriends(userId);
    }

    // 添加好友
    @PostMapping("/friends/add")
    public String addFriend(@RequestParam("userId") Integer userId, @RequestParam("friendId") Integer friendId) {
        return friendsService.addFriend(userId, friendId);
    }

    // 删除好友
    @DeleteMapping("/friends/delete")
    public String deleteFriend(@RequestParam("userId") Integer userId, @RequestParam("friendId") Integer friendId) {
        return friendsService.deleteFriend(userId, friendId);
    }

    // 发送消息
    @PostMapping("/messages/send")
    public String sendMessage(@RequestParam("senderId") Integer senderId,
                              @RequestParam("receiverId") Integer receiverId,
                              @RequestParam("content") String content) {
        return friendsService.sendMessage(senderId, receiverId, content);
    }

    // 获取聊天记录
    @GetMapping("/messages/list")
    public List<Messages> getMessages(@RequestParam("senderId") Integer senderId,
                                      @RequestParam("receiverId") Integer receiverId) {
        return friendsService.getMessages(senderId, receiverId);
    }
}
